Component({
  mixins: [],
  data: {
    listData:[
    ],
    putList:[
      {
        'name':'type1',
        'type':1,
        'title':'投放到对应的商品详情页',
        'bool':false,
      },
      {
        'name':'type2',
        'type':2,
        'title':'投放到对应的商品轮播图',
        'bool':false,
      },
      {
        'name':'type3',
        'type':3,
        'title':'投放到店铺的首页广告位',
        'bool':false,
      },
      {
        'name':'type4',
        'type':4,
        'title':'投放到小程序首页广告位',
        'bool':true,
      },
    ],
    visible1: false,
    visible2: false,
    visible3: false,
    groupVisible: false,
    total: 0,
    page: 1,
    pagesize: 5,
    modals1:false,

    put_videos_id:'',
    put_type:'',
    video_url:'',
    put_type_arr:[],
    type1:0,
    type2:0,
    type3:0,
    type4:0,
  },
  props: {},
  didMount() {
    this.getaty(1);
  },
  didUpdate() {},
  didUnmount() {},
  methods: {
    openOver({ target: { dataset: { index } } }) {
      this.setData({ [`visible${index}`]: !this.data[`visible${index}`] });
    },
    //打开新页面
    openNew(){
      my.redirectTo({ url: '/page/testc/test' })
    },
    //复制
    myCopy() {
      var that = this;
        my.setClipboard({
        text: that.data.video_url, // 剪贴板数据
        success: (res) => {
          console.log(res);
          my.alert({
            content: '复制成功！'
          });
        },
      });
    },
    // 列表数据
    getaty(pageNum) {
      var apiurl = 'App.ShopRedsVideo.GetLists';
      var params = {
        "page": pageNum,
        "pagesize": this.data.pagesize,
      };
      var app = getApp();
      var self = this;
      app.xdapis(apiurl, params, function (e) {
        my.hideLoading();
        // my.alert({ title: JSON.stringify(e) });
        self.setData({
          listData: e.list,
          total: e.page_info.total,
          page: e.page_info.page,
          pagesize: e.page_info.pagesize
        });
      });
    },
    // 打开模态框
    openModel(e){
      var name = e.currentTarget.dataset.name;
      var videos_id = e.currentTarget.dataset.videos_id;
      var video_url = e.currentTarget.dataset.video;
      this.setData({ 
        [name]: true,
        put_videos_id:videos_id,
        video_url:video_url
      });
    },
    //关闭模态框
    closeModel(e) {
      var name = e.currentTarget.dataset.name;
      this.setData({ [name]: false });
    },
    onChange(e) {
      let {
        detail: { value },
        currentTarget: { dataset }
      } = e;
      let { name } = dataset;
      console.log(name + ' onChange:', value);
      console.log(e);
      var type = e.currentTarget.dataset.value;
      var arr = this.data.put_type_arr;

      this.setData({ [name]: type });
      console.log(this.data);
    },
    handleSubmit(){
      var put_videos_id = this.data.put_videos_id;
      var type1=this.data.type1;
      var type2=this.data.type2;
      var type3=this.data.type3;
      var type4=this.data.type4;
      if (!type4) {
        my.alert({ content: '请选择投放位置!' });
        return false;
      }
      if( put_videos_id ){
        if( type4 == 4 ){
          var apiurl = 'App.ShopRedsVideo.Put';
          var params = {
            "videos_id": put_videos_id,
            "type": type4,
          };
          var app = getApp();
          var self = this;
          app.xdapis(apiurl, params, function (e) {
            my.hideLoading();
            self.setData({ modals1: false });
            my.alert({ title: '投放成功!' });
          });
        }
      }
    }
  },
});
